{include file='../public/header.html'}

<div class="main">
	{include file='../public/left.html'}
	<div class="right">
		<nav aria-label="breadcrumb">
			<ol class="breadcrumb">
				<li class="breadcrumb-item"><a href="#">Home</a></li>
				<li class="breadcrumb-item"><a href="#">Library</a></li>
				<li class="breadcrumb-item active" aria-current="page">Data</li>
			</ol>
		</nav>
	<div class="page-container">
	<!-- MAIN CONTENT-->
	<div class="main-content">
		<div class="section__content section__content--p30">
			<div class="container-fluid">
				<div class="row">
					<div class="col-lg-9">
						<div class="table-responsive table--no-card m-b-30">
							<table class="table table-borderless table-striped table-earning">
								<thead>
								<tr>
									<th class="th_left">执行</th>
									<th>代号</th>
									<th>状态</th>
									<th>总时常</th>
									<th>剩余时常</th>
									<th class="th_left">操作</th>
								</tr>
								</thead>
								<tbody>
								{foreach $task_list as $ts_key => $ts_val}
									<tr>
										<td onclick="startTask(this)" data-id="{$ts_val.id}">
											<div class="table-data-feature">
												<span class="item"><i class="zmdi zmdi-play"></i></span>
											</div>
										</td>
										<td>{$ts_val.title}</td>
										<td><a class="{$ts_val.status_class}" style="color:#fff">{$ts_val.status}</a></td>
										<td>{$ts_val.avg_time}</td>
										<td id="remai_time" data-remai="{$ts_val.remai_time}">{$ts_val.remai_times}</td>
										<td>
											<div class="table-data-feature">
												<a class="item"><i class="zmdi zmdi-edit"></i></a>
												<a class="item" onclick="removeTask(this,{$ts_val.id})"><i class="zmdi zmdi-delete"></i></a>
											</div>
										</td>
									</tr>
								{/foreach}
								</tbody>
							</table>
						</div>
					</div>
					<div class="col-lg-3">
						<div class="au-card au-card--bg-blue m-b-30">
							<div class="au-card-inner">
								<div class="table-responsive">
									<table class="table table-top-countries">
										<thead class="task_mune">
										<tr>
											<th>任务</th>
											<th>时间</th>
										</tr>
										</thead>
										<tbody>
										{foreach $menu_list as $mu_key => $mu_val name=bg_menu}
										{if $smarty.foreach.bg_menu.index < 9}
											<tr onclick="addTaskList(this)" data-id="{$mu_val.id}">
												<td>{$mu_val.title}</td>
												<td>{$mu_val.avg_time}</td>
											</tr>
										{/if}
										{/foreach}
										</tbody>
									</table>
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-lg-8">
						<!-- USER DATA-->
						<div class="user-data m-b-30">
							<h3 class="title-3 m-b-30">
								<i class="zmdi zmdi-account-calendar"></i>战略行动</h3>
							<div class="filters m-b-45">
								<div class="rs-select2--dark rs-select2--sm rs-select2--border">
									<button class="btn btn-primary btn-gund" data-toggle="modal" data-target="#add_task_menu">新计划</button>
								</div>
							</div>
							<div class="table-responsive table-data">
								<table class="table">
									<thead>
									<tr>
										<td>
											<label class="au-checkbox">
												<input type="checkbox">
												<span class="au-checkmark"></span>
											</label>
										</td>
										<td>任务名</td>
										<td>单次时间/分钟</td>
										<td>完成数/总次数</td>
										<td>类型</td>
										<td></td>
										<td></td>
									</tr>
									</thead>
									<tbody>
									{foreach $menu_list as $mu_key => $mu_val}
									<tr>
										<td>
											<label class="au-checkbox">
												<input type="checkbox">
												<span class="au-checkmark"></span>
											</label>
										</td>
										<td>
											<div class="table-data__info">
												<h6>{$mu_val.title}</h6>
											</div>
										</td>
										<td>
											<span class="role user">{$mu_val.avg_time}</span>
										</td>
										<td>
											<span class="role member">{$mu_val.ok_chapter}/{$mu_val.chapter}</span>
										</td>
										<td>
											<div class="table-data__info">
												<h6><span>{$mu_val.type}</h6>
											</div>
										</td>
										<td>
											<div class="table-data-feature">
												<a class="item" onclick="upByTaskMenu(this,{$mu_val.id})"><i class="zmdi zmdi-long-arrow-up"></i></a>
												<a class="item"><i class="zmdi zmdi-edit"></i></a>
												<a class="item"><i class="zmdi zmdi-delete"></i></a>
											</div>
										</td>
									</tr>
									{/foreach}
									</tbody>
								</table>
							</div>
							<div class="user-data__footer">
								<button class="au-btn au-btn-load">load more</button>
							</div>
						</div>
						<!-- END USER DATA-->
					</div>
					<div class="col-lg-4">
						<!-- TOP CAMPAIGN-->
						<div class="top-campaign">
							<h3 class="title-3 m-b-30">排行榜</h3>
							<div class="table-responsive">
								<table class="table table-top-campaign">
									<tbody>
									<tr>
										<td>1. Australia</td>
										<td>$70,261.65</td>
									</tr>
									<tr>
										<td>2. United Kingdom</td>
										<td>$46,399.22</td>
									</tr>
									<tr>
										<td>3. Turkey</td>
										<td>$35,364.90</td>
									</tr>
									<tr>
										<td>4. Germany</td>
										<td>$20,366.96</td>
									</tr>
									<tr>
										<td>5. France</td>
										<td>$10,366.96</td>
									</tr>
									<tr>
										<td>3. Turkey</td>
										<td>$35,364.90</td>
									</tr>
									<tr>
										<td>4. Germany</td>
										<td>$20,366.96</td>
									</tr>
									<tr>
										<td>5. France</td>
										<td>$10,366.96</td>
									</tr>
									<tr>
										<td>3. Turkey</td>
										<td>$35,364.90</td>
									</tr>
									<tr>
										<td>4. Germany</td>
										<td>$20,366.96</td>
									</tr>
									<tr>
										<td>5. France</td>
										<td>$10,366.96</td>
									</tr>
									<tr>
										<td>4. Germany</td>
										<td>$20,366.96</td>
									</tr>
									</tbody>
								</table>
							</div>
						</div>
						<!--  END TOP CAMPAIGN-->
					</div>
				</div>
			<div class="row">
				<div class="col-md-12">
					<!-- DATA TABLE -->
					<h3 class="title-5 m-b-35">data table</h3>
					<div class="table-data__tool">
						<div class="table-data__tool-left">
							<div class="rs-select2--light rs-select2--md">
								<select class="js-select2" name="property">
									<option selected="selected">All Properties</option>
									<option value="">Option 1</option>
									<option value="">Option 2</option>
								</select>
								<div class="dropDownSelect2"></div>
							</div>
							<div class="rs-select2--light rs-select2--sm">
								<select class="js-select2" name="time">
									<option selected="selected">Today</option>
									<option value="">3 Days</option>
									<option value="">1 Week</option>
								</select>
								<div class="dropDownSelect2"></div>
							</div>
							<button class="au-btn-filter">
								<i class="zmdi zmdi-filter-list"></i>filters</button>
						</div>
						<div class="table-data__tool-right">
							<button class="au-btn au-btn-icon au-btn--green au-btn--small">
								<i class="zmdi zmdi-plus"></i>add item</button>
							<div class="rs-select2--dark rs-select2--sm rs-select2--dark2">
								<select class="js-select2" name="type">
									<option selected="selected">Export</option>
									<option value="">Option 1</option>
									<option value="">Option 2</option>
								</select>
								<div class="dropDownSelect2"></div>
							</div>
						</div>
					</div>
					<div class="table-responsive table-responsive-data2">
						<table class="table table-data2">
							<thead>
							<tr>
								<th>
									<label class="au-checkbox">
										<input type="checkbox">
										<span class="au-checkmark"></span>
									</label>
								</th>
								<th>name</th>
								<th>email</th>
								<th>description</th>
								<th>date</th>
								<th>status</th>
								<th>price</th>
								<th></th>
							</tr>
							</thead>
							<tbody>
							<tr class="tr-shadow">
								<td>
									<label class="au-checkbox">
										<input type="checkbox">
										<span class="au-checkmark"></span>
									</label>
								</td>
								<td>Lori Lynch</td>
								<td>
									<span class="block-email">lori@example.com</span>
								</td>
								<td class="desc">Samsung S8 Black</td>
								<td>2018-09-27 02:12</td>
								<td>
									<span class="status--process">Processed</span>
								</td>
								<td>$679.00</td>
								<td>
									<div class="table-data-feature">
										<button class="item" data-toggle="tooltip" data-placement="top" title="Send">
											<i class="zmdi zmdi-mail-send"></i>
										</button>
										<button class="item" data-toggle="tooltip" data-placement="top" title="Edit">
											<i class="zmdi zmdi-edit"></i>
										</button>
										<button class="item" data-toggle="tooltip" data-placement="top" title="Delete">
											<i class="zmdi zmdi-delete"></i>
										</button>
										<button class="item" data-toggle="tooltip" data-placement="top" title="More">
											<i class="zmdi zmdi-more"></i>
										</button>
									</div>
								</td>
							</tr>
							<tr class="spacer"></tr>
							<tr class="tr-shadow">
								<td>
									<label class="au-checkbox">
										<input type="checkbox">
										<span class="au-checkmark"></span>
									</label>
								</td>
								<td>Lori Lynch</td>
								<td>
									<span class="block-email">john@example.com</span>
								</td>
								<td class="desc">iPhone X 64Gb Grey</td>
								<td>2018-09-29 05:57</td>
								<td>
									<span class="status--process">Processed</span>
								</td>
								<td>$999.00</td>
								<td>
									<div class="table-data-feature">
										<button class="item" data-toggle="tooltip" data-placement="top" title="Send">
											<i class="zmdi zmdi-mail-send"></i>
										</button>
										<button class="item" data-toggle="tooltip" data-placement="top" title="Edit">
											<i class="zmdi zmdi-edit"></i>
										</button>
										<button class="item" data-toggle="tooltip" data-placement="top" title="Delete">
											<i class="zmdi zmdi-delete"></i>
										</button>
										<button class="item" data-toggle="tooltip" data-placement="top" title="More">
											<i class="zmdi zmdi-more"></i>
										</button>
									</div>
								</td>
							</tr>
							<tr class="spacer"></tr>
							<tr class="tr-shadow">
								<td>
									<label class="au-checkbox">
										<input type="checkbox">
										<span class="au-checkmark"></span>
									</label>
								</td>
								<td>Lori Lynch</td>
								<td>
									<span class="block-email">lyn@example.com</span>
								</td>
								<td class="desc">iPhone X 256Gb Black</td>
								<td>2018-09-25 19:03</td>
								<td>
									<span class="status--denied">Denied</span>
								</td>
								<td>$1199.00</td>
								<td>
									<div class="table-data-feature">
										<button class="item" data-toggle="tooltip" data-placement="top" title="Send">
											<i class="zmdi zmdi-mail-send"></i>
										</button>
										<button class="item" data-toggle="tooltip" data-placement="top" title="Edit">
											<i class="zmdi zmdi-edit"></i>
										</button>
										<button class="item" data-toggle="tooltip" data-placement="top" title="Delete">
											<i class="zmdi zmdi-delete"></i>
										</button>
										<button class="item" data-toggle="tooltip" data-placement="top" title="More">
											<i class="zmdi zmdi-more"></i>
										</button>
									</div>
								</td>
							</tr>
							<tr class="spacer"></tr>
							<tr class="tr-shadow">
								<td>
									<label class="au-checkbox">
										<input type="checkbox">
										<span class="au-checkmark"></span>
									</label>
								</td>
								<td>Lori Lynch</td>
								<td>
									<span class="block-email">doe@example.com</span>
								</td>
								<td class="desc">Camera C430W 4k</td>
								<td>2018-09-24 19:10</td>
								<td>
									<span class="status--process">Processed</span>
								</td>
								<td>$699.00</td>
								<td>
									<div class="table-data-feature">
										<button class="item" data-toggle="tooltip" data-placement="top" title="Send">
											<i class="zmdi zmdi-mail-send"></i>
										</button>
										<button class="item" data-toggle="tooltip" data-placement="top" title="Edit">
											<i class="zmdi zmdi-edit"></i>
										</button>
										<button class="item" data-toggle="tooltip" data-placement="top" title="Delete">
											<i class="zmdi zmdi-delete"></i>
										</button>
										<button class="item" data-toggle="tooltip" data-placement="top" title="More">
											<i class="zmdi zmdi-more"></i>
										</button>
									</div>
								</td>
							</tr>
							</tbody>
						</table>
					</div>

			</div>
		</div>
	</div>
</div>
	{include file='./add_menu.html'}
</div>
<script type="text/javascript">
	var task = 0;  //任务状态
	var task_dom = ''; //操作任务节点
	var task_inter = '';//定时任务
	
	function addTaskList(_this)
	{
		var data = {};
			data.id = $(_this).data('id');
		var url = '/index/task/addTask';

		on_ajax(url,data,'POST','json',1);
	}
	
	function startTask(_this){
		if(task == 1 && task_dom != _this){
			alert('有任务正在进行');
			return;
		}
		if(task_dom == _this){
			endTask(task_dom);
			return;
		}
		
		task_dom = _this;
		task_inter = window.setInterval("carryTask()",1000)//单位是毫秒
		task = 1;
		$(task_dom).find('i').removeClass();
		$(task_dom).find('i').addClass('zmdi zmdi-stop');

		var data = {};
			data.id = $(_this).data('id');
			data.status = 2;
			data.start_time = Date.parse(new Date()) / 1000;
		var url = '/index/task/editTask';

		on_ajax(url,data,'POST','json',2);
	}

	//暂停任务
	function endTask(_this){
		var data = {};
			data.id = $(task_dom).data('id');
			data.status = 1;
			data.remai_time = $(task_dom).siblings('#remai_time').data('remai');
		var url = '/index/task/editTask';

		on_ajax(url,data,'POST','json',2);

		$(task_dom).find('i').removeClass();
		$(task_dom).find('i').addClass('zmdi zmdi-play');
		clearInterval(task_inter);
		task = 0;
		task_dom = '';
		task_inter = '';
		return;
	}

	//移除任务
	function removeTask(_this,id){
		var data = {};
			data.id = id;
			data.is_del = 2;
			data.end_time = $(task_dom).siblings('#remai_time').data('remai');
		var url = '/index/task/editTask';

		on_ajax(url,data,'POST','json',1);
		return;
	}

	//任务排序
	function upByTaskMenu(_this,id){
		var data = {};
		data.id = id;
		data.by_time = Date.parse(new Date()) / 1000;
		var url = '/index/task/editTaskMenu';

		on_ajax(url,data,'POST','json',1);
		return;
	}
	
	//任务进行
	function carryTask(){
		var time = $(task_dom).siblings('#remai_time').data('remai');
		if(time <= 0){
			var data = {};
			data.id = $(task_dom).data('id');
			data.status = 3;
			data.remai_time = 0;
			var url = '/index/task/editTask';

			on_ajax(url,data,'POST','json',1);

			clearInterval(task_inter);
			task = 0;
			task_dom = '';
			task_inter = '';

			return;
		}
		
		var min = parseInt(time/60);
		var sec = time % 60;
		var text = check(min) + ':' + check(sec);
		
		$(task_dom).siblings('#remai_time').text(text);
		$(task_dom).siblings('#remai_time').data('remai',time-1);
	}
	

</script>
{include file='../public/foot.html'}